home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d7
/
lanuts.arc
/
USERLIST.C
< prev
next >
Wrap
Text File
|
1991-10-30
|
6KB
|
221 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#include <direct.h>
#include <conio.h>
#include "lantasti.h"
#define DOS 0x21
#define NETBIOS 0x5C
#define DELIM "+, "
/* structure to allow easy access to both segment and offset portions of
far pointers */
#define LIST_SIZE 50
#define NAME_SIZE 20
typedef struct LIST {
int num_servers;
char server[LIST_SIZE][NAME_SIZE];
} LIST;
/* definitions to save typing time */
#define C_SERVER list->server[i]
/***********************************************************************
Delete leading and trailing blanks.
***********************************************************************/
void dltb(string)
char *string;
{
int i;
i = strspn(string, " ");
if (i) strcpy(string,string + i);
i = strlen(string) - 1;
while (i && (string[i] == ' ')) {
string[i--] = '\0';
}
}
/* getstring ********************************************************************
Get a string from the console -- takes a pointer to a string buffer, the
longest permissible length and two switches. The empty switch determines
whether or not the user is allowed to enter an empty string. If TRUE, he
can, if FALSE, he must enter something. The shown switch determines
whether or not input is echoed to the screen, TRUE if echoed, FALSE if
invisible
*****************************************************************************/
void getstring(prompt,buffer,length,empty,shown)
char *prompt,*buffer;
int length,empty,shown;
{
fprintf(stdout,"%s",prompt);
fgets(buffer,length,stdin);
if (buffer[strlen(buffer) - 1] == '\n') buffer[strlen(buffer) - 1] = 0;
while (!(strlen(buffer) || empty)) {
fprintf(stdout,"%s",prompt);
fgets(buffer,length,stdin);
if (buffer[strlen(buffer) - 1] == '\n') buffer[strlen(buffer) - 1] = 0;
}
}
/* error ********************************************************************
*****************************************************************************/
void error(code,message)
int code;
char *message;
{
char *ptr;
if (code) {
ptr = get_error_text(code);
puts(ptr);
}
else puts(message);
}
/* get_active_servers ********************************************************************
*****************************************************************************/
void get_active_servers(list)
LIST *list;
{
char buffer[17];
int index,result;
index = 0;
result = get_active_server(buffer,index);
while (result) {
strcpy(list->server[list->num_servers++],buffer);
if (list->num_servers >= LIST_SIZE) {
puts("Warning: Too many servers. Only the first 50 can be used.");
break;
}
result = get_active_server(buffer,++index);
}
}
/* process_server_list ********************************************************************
*****************************************************************************/
void process_server_list(string,list)
char *string;
LIST *list;
{
char *ptr;
ptr = strtok(string,DELIM);
while (ptr !=NULL) {
if (!strcmp(ptr,"/HELP")) {
puts("USERLIST utility for LANtastic -- Copyright 1989 by SoftMagic, Inc.");
puts("All rights reserved. LANtastic is a trademark of Artisoft, Inc.\n");
puts("Usage: USERLIST <server list> [/OPTIONS]");
puts(" A question mark in the list causes the program to prompt the user");
puts(" for input. USERLIST with no arguments will list users for all");
puts(" active servers.\n");
puts("Available options are:");
puts("/HELP - display this documentation");
exit(0);
break;
}
if (*ptr == '*') {
list->num_servers = 0;
get_active_servers(list);
break;
}
else {
strcpy(list->server[list->num_servers++],ptr);
}
if (list->num_servers >= LIST_SIZE ) {
puts("Warning: Too many servers. Only the first 50 will be used.");
break;
}
ptr = strtok(NULL," ,");
}
/* if no servers are given, list out of everything */
if (list->num_servers == 0) get_active_servers(list);
}
/* scan_command_line ********************************************************************
*****************************************************************************/
scan_command_line(argc,argv,list)
int argc;
char *argv[];
LIST *list;
{
int i;
char buffer[1];
buffer[0] = 0;
list->num_servers = 0;
if (argc < 2) process_server_list(buffer,list);
for (i = 1;i < argc; i++) {
strupr(argv[i]);
process_server_list(argv[i],list);
}
}
/* do_userlist ********************************************************************
*****************************************************************************/
int do_userlist(list)
LIST *list;
{
int i,j,num_users;
char userlist_buffer[128];
ACTIVE_USER user;
for (i = 0; i < list->num_servers; i++) {
/* see if we've got any "?"s in the list */
if (C_SERVER[0] == '?') {
getstring("Server: ",userlist_buffer,128,FALSE,TRUE);
list->num_servers = i;
process_server_list(userlist_buffer,list);
}
dltb(C_SERVER);
printf("\nUsers on server %s:\n",C_SERVER);
j = num_users = 0;
sprintf(userlist_buffer,"\\\\%s",C_SERVER);
while (!get_user_info(userlist_buffer,j++,&user)) {
num_users++;
dltb(user.name); dltb(user.machine);
printf(" %s on machine %s\n",user.name,user.machine);
}
printf("(%d users)\n",num_users);
}
}
/* main ********************************************************************
*****************************************************************************/
int main(argc,argv)
int argc;
char *argv[];
{
LIST list; /*server, user and password lists*/
int serverno; /*index into serverlist*/
#ifdef SHAREWARE
puts("USERLIST utility for LANtastic -- Copyright 1989 by SoftMagic, Inc.");
puts("All rights reserved. Thanks for trying this unregistered Shareware edition!\n");
#endif
scan_command_line(argc,argv,&list);
if (list.num_servers > 0) do_userlist(&list);
else error(FALSE,"You are not logged in to any servers.");
return(0);
}